package com.imedway.ihe.client;

import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;

import javax.xml.namespace.QName;
import javax.xml.ws.Service;

import org.openehealth.ipf.commons.ihe.xds.core.ebxml.ebxml30.RetrieveDocumentSetRequestType;
import org.openehealth.ipf.commons.ihe.xds.core.ebxml.ebxml30.RetrieveDocumentSetResponseType;
import org.openehealth.ipf.commons.ihe.xds.core.ebxml.ebxml30.RetrieveDocumentSetRequestType.DocumentRequest;
import org.openehealth.ipf.commons.ihe.xds.iti43.Iti43PortType;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import lombok.extern.slf4j.Slf4j;

/**
 * @author zhongyj <1126834403@qq.com><br/>
 * @date 2024/7/3
 */
@Slf4j
@RestController
@RequestMapping("iti43")
public class Iti43PortTypeClient {

    @PostMapping
    public void iti43() throws MalformedURLException {
        URL wsdlUrl = new URL("http://localhost:8080/services/iti43?wsdl");
        QName serviceName = new QName("http://service.ihe.imedway.com/", "Iti43PortTypeImplService");
        Service service = Service.create(wsdlUrl, serviceName);
        Iti43PortType myWebService = service.getPort(Iti43PortType.class);
        RetrieveDocumentSetRequestType body = new RetrieveDocumentSetRequestType();
        List<DocumentRequest> documentRequestLists = new ArrayList<DocumentRequest>();
        DocumentRequest documentRequest = new DocumentRequest();
        documentRequest.setDocumentUniqueId("1.42.20101110141555.15");
        documentRequest.setHomeCommunityId(null);
        documentRequest.setRepositoryUniqueId("1.19.6.24.109.42.1.5");
        documentRequestLists.add(documentRequest);
        body.getDocumentRequest().addAll(documentRequestLists);
        RetrieveDocumentSetResponseType retrieveDocumentSetResponseType = myWebService.documentRepositoryRetrieveDocumentSet(body);
        log.info(retrieveDocumentSetResponseType.getDocumentResponse().get(0).getDocumentUniqueId());

    }


}